package io.xiaojl.xj2ee.modules.sys.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import io.xiaojl.xj2ee.modules.sys.entity.SysUserEntity;

/**  
 * <p>Title: SysUserRepository</p>  
 *
 * <p>Description: 实现基本的CRUD还有分页操作</p>  
 *
 * @author jilong.xiao  
 * @date 2018年9月27日  
 */
public interface SysUserRepository extends JpaRepository<SysUserEntity, Long> ,JpaSpecificationExecutor<SysUserEntity> {

	/**  
	 * <p>Title: queryAllMenuId</p>  
	 * <p>Description: 查询用户的所有菜单ID</p>  
	 * @param userId
	 * @return  
	 */ 
	@Query(value="select distinct rm.menu_id from sys_user_role ur "
				+" LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id  "
				+" where ur.userId =:userId" , nativeQuery=true) //nativeQuery = true，即使用原生的sql语句查询。
	List<Long> queryAllMenuId(@Param("userId")Long userId);

	/**  
	 * <p>Title: queryAllPerms</p>  
	 * <p>Description:  查询用户的所有权限</p>  
	 * @param userId
	 * @return  
	 */ 
	@Query(value="select m.perms from sys_user_role ur "
			 +" LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id "
			 +" LEFT JOIN sys_menu m on rm.menu_id = m.menu_id  "
			 +" where ur.userId =:userId" , nativeQuery=true) //nativeQuery = true，即使用原生的sql语句查询。
	List<String> queryAllPerms(@Param("userId")Long userId);

}
